﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SiteAdm.Master" AutoEventWireup="true"
    CodeBehind="ConsultaServicos.aspx.cs" Inherits="AgileSaude.Web.Clinica.ConsultaServicos" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <!-- TÍTULO DA PÁGINA -->
    <div class="area-titulo container-fluid">
        <div class="container">
            <h2 class="titulo">
                Consulta de Serviços Prestados</h2>
        </div>
    </div>
    <!-- FIM DO TÍTULO -->
    <div class="container">
        <div class="row">
            <div class="area-formulario">
                <div class="form-group">
                <label class="col-sm-3 control-label">
                        Mês</label>
                    <div class="col-sm-7">
                        <asp:TextBox ID="txtDataIni" runat="server" CssClass="form-control"></asp:TextBox>
                        <asp:CalendarExtender ID="CalendarExtender1" BehaviorID="calendar1" runat="server"
                            Enabled="True" Format="MM/yyyy" TargetControlID="txtDataIni" OnClientShown="onCalendarShown"
                            OnClientHidden="onCalendarHidden">
                        </asp:CalendarExtender>
                        <%--<asp:CalendarExtender ID="txtDataIni_CalendarExtender" runat="server" Enabled="True"
                            TargetControlID="txtDataIni">
                        </asp:CalendarExtender>--%>
                    </div>
                </div>
                <%--<div class="form-group">
                    <label class="col-sm-3 control-label">
                        Data Final</label>
                    <div class="col-sm-7">
                        <asp:TextBox ID="txtDataFim" runat="server" CssClass="form-control"></asp:TextBox>
                        <asp:CalendarExtender ID="txtDataFim_CalendarExtender" runat="server" Enabled="True"
                            TargetControlID="txtDataFim">
                        </asp:CalendarExtender>
                    </div>
                </div>--%>
            </div>
            <div class="row">
                <div class="form-group">
                    <asp:LinkButton ID="btnConsultar" runat="server" class="btn btn-md btn-success" Text="&#xf067; Consultar"
                        OnClick="btnConsultar_Click" />
                </div>
            </div>
        </div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <div class="row">
                    <asp:GridView ID="gvConsulta" runat="server" AutoGenerateColumns="False" SkinID="CadastrosGrid"
                        CssClass="table table-striped table-bordered table-hover" DataKeyNames="IdPedido"
                        AllowSorting="true" OnRowCommand="gvConsulta_RowCommand" OnSorting="gvConsulta_Sorting"
                        OnRowDataBound="gvConsulta_RowDataBound" PageSize="20" OnPageIndexChanging="gvConsulta_PageIndexChanging"
                        AllowPaging="true">
                        <Columns>
                            <asp:BoundField DataField="Data" HeaderText="Data" SortExpression="Data">
                                <ItemStyle HorizontalAlign="Left" BorderColor="White" Width="10%" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Numero" HeaderText="Número" SortExpression="Numero">
                                <ItemStyle HorizontalAlign="Left" BorderColor="White" Width="10%" />
                            </asp:BoundField>
                            <asp:BoundField DataField="UsuarioNome" HeaderText="Cliente" SortExpression="UsuarioNome">
                                <ItemStyle HorizontalAlign="Left" BorderColor="White" Width="20%" />
                            </asp:BoundField>
                            <asp:BoundField DataField="MedicoNome" HeaderText="Médico" SortExpression="MedicoNome">
                                <ItemStyle HorizontalAlign="Left" BorderColor="White" Width="20%" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Voucher" HeaderText="Voucher" SortExpression="Voucher">
                                <ItemStyle HorizontalAlign="Left" BorderColor="White" Width="20%" />
                            </asp:BoundField>
                            <%--<asp:TemplateField HeaderText="Opções">
                                <ItemStyle HorizontalAlign="Center" BorderColor="White" Width="20%" />
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkEditar" class="btn btn-md btn-success" runat="server" CommandName="Editar"
                                        ToolTip="Editar"><i class="fa fa-pencil fa-lg"></i></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>--%>
                        </Columns>
                    </asp:GridView>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    <script type="text/javascript">


        var cal1;
        var cal2;


        function pageLoad() {
            cal1 = $find("calendar1");
            cal2 = $find("calendar2");


            modifyCalDelegates(cal1);
            modifyCalDelegates(cal2);
        }


        function modifyCalDelegates(cal) {
            //we need to modify the original delegate of the month cell.
            cal._cell$delegates = {
                mouseover: Function.createDelegate(cal, cal._cell_onmouseover),
                mouseout: Function.createDelegate(cal, cal._cell_onmouseout),


                click: Function.createDelegate(cal, function (e) {
                    /// <summary>
                    /// Handles the click event of a cell
                    /// </summary>
                    /// <param name="e" type="Sys.UI.DomEvent">The arguments for the event</param>


                    e.stopPropagation();
                    e.preventDefault();


                    if (!cal._enabled) return;


                    var target = e.target;
                    var visibleDate = cal._getEffectiveVisibleDate();
                    Sys.UI.DomElement.removeCssClass(target.parentNode, "ajax__calendar_hover");
                    switch (target.mode) {
                        case "prev":
                        case "next":
                            cal._switchMonth(target.date);
                            break;
                        case "title":
                            switch (cal._mode) {
                                case "days": cal._switchMode("months"); break;
                                case "months": cal._switchMode("years"); break;
                            }
                            break;
                        case "month":
                            //if the mode is month, then stop switching to day mode.
                            if (target.month == visibleDate.getMonth()) {
                                //this._switchMode("days");
                            } else {
                                cal._visibleDate = target.date;
                                //this._switchMode("days");
                            }
                            cal.set_selectedDate(target.date);
                            cal._switchMonth(target.date);
                            cal._blur.post(true);
                            cal.raiseDateSelectionChanged();
                            break;
                        case "year":
                            if (target.date.getFullYear() == visibleDate.getFullYear()) {
                                cal._switchMode("months");
                            } else {
                                cal._visibleDate = target.date;
                                cal._switchMode("months");
                            }
                            break;


                        //                case "day":     
                        //                    this.set_selectedDate(target.date);     
                        //                    this._switchMonth(target.date);     
                        //                    this._blur.post(true);     
                        //                    this.raiseDateSelectionChanged();     
                        //                    break;     
                        case "today":
                            cal.set_selectedDate(target.date);
                            cal._switchMonth(target.date);
                            cal._blur.post(true);
                            cal.raiseDateSelectionChanged();
                            break;
                    }


                })
            }


        }


        function onCalendarShown(sender, args) {
            //set the default mode to month
            sender._switchMode("months", true);
            changeCellHandlers(cal1);
        }




        function changeCellHandlers(cal) {


            if (cal._monthsBody) {


                //remove the old handler of each month body.
                for (var i = 0; i < cal._monthsBody.rows.length; i++) {
                    var row = cal._monthsBody.rows[i];
                    for (var j = 0; j < row.cells.length; j++) {
                        $common.removeHandlers(row.cells[j].firstChild, cal._cell$delegates);
                    }
                }
                //add the new handler of each month body.
                for (var i = 0; i < cal._monthsBody.rows.length; i++) {
                    var row = cal._monthsBody.rows[i];
                    for (var j = 0; j < row.cells.length; j++) {
                        $addHandlers(row.cells[j].firstChild, cal._cell$delegates);
                    }
                }


            }
        }


        function onCalendarHidden(sender, args) {


            if (sender.get_selectedDate()) {
                if (cal1.get_selectedDate() && cal2.get_selectedDate() && cal1.get_selectedDate() > cal2.get_selectedDate()) {
                    alert('The "From" Date should smaller than the "To" Date, please reselect!');
                    sender.show();
                    return;
                }
                //get the final date
                var finalDate = new Date(sender.get_selectedDate());
                var selectedMonth = finalDate.getMonth();
                finalDate.setDate(1);
                if (sender == cal2) {
                    // set the calender2's default date as the last day
                    finalDate.setMonth(selectedMonth + 1);
                    finalDate = new Date(finalDate - 1);
                }
                //set the date to the TextBox
                sender.get_element().value = finalDate.format(sender._format);
            }
        }


    </script>
</asp:Content>
